define("register",["jquery","validate","md5","idcode"],function ($) {
		return {
			init:function () {
				$.idcode.setCode()
				$.validator.addMethod("checkTel",function (val,ele) {
					 return /^[1][3,5,6,7,8][0-9]{9}$/.test(val)
				},'手机号码不合法')
				$.validator.addMethod("checkEmail",function (val,ele) {
					return /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/.test(val)
				},"邮箱格式不正确")
				$.validator.addMethod("checkName",function (val,ele) {
					return /[\u4e00-\u9fa5]+/.test(val)
				},"请输入中文名称")
				$("form").validate({
					rules:{
						utel:{
							required:true,
							checkTel:true,
							remote:"../../server/isExitPhone.php"
						},
						upwd:{
							required:true,
							rangelength:[6,12]
						},
						uemail:{
							
							checkEmail:true
						},
						reallyname:{
							checkName:true
						}
						
					},
					messages:{
						utel:{
							required:"请输入手机号",
							remote:"手机号已存在"
						},
						upwd:{
							required:"请输入密码",
							rangelength:"密码长度为{0}-{1}"
						}
					},
					submitHandler:function () {
						var IsBy = $.idcode.validateCode()
						var formData=new FormData()
						console.log(formData);
						if(IsBy){
							if($(".ck")[0].checked){
								var $data=$("form").serializeArray()
								$data.forEach((ele,index)=>{
									if(ele.name!="Txtidcode"&&ele.name!="check"){
										if(ele.name=="upwd"){
											formData.append(ele.name,$.md5(ele.value))
										}else{
											formData.append(ele.name,ele.value)
										}
										
									}
								})
								$.ajax({
									url:"../../server/register.php",
									type:"post",
									dataType:"json",
									data:formData,
									processData:false,
									contentType:false
									
								}).then(function (res) {
									if(res.status==1){
										confirm("注册成功，是否现在登录？")?location="login.html":location.reload(true)
									}else{
										alert("注册失败")
									}
									
								})
							}else{
								$(".hint_wrap").css("display","block")
							}
						}
						
						return false
					},
					errorPlacement:function (err,ele) {
						//console.log(arguments);
						$(ele).after(err)
						$(ele).after($("<div class='error'></div>"))
						
					},
					success:function (err,ele) {
						$(ele).next("div").css("background","none")
					}
				})
				
			},
			hint(){
				function click(ele) {
					ele.click(function () {
						$(".hint_wrap").css("display","none")
					})
				}
				click($(".h_top span"))
				click($(".h_center input"))
			}
			
		}
})